//
//  PlatformTabBarController.m
//  CarLifes
//
//  Created by yu on 2017/6/14.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "PlatformTabBarController.h"
#import "NavigationController.h"
#import "HomeViewController.h"
#import "ListViewController.h"
#import "AlarmViewController.h"
#import "MeViewController.h"
#import "UIImage+CLImage.h"

@interface PlatformTabBarController ()

@end

@implementation PlatformTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupAllChildViewControllers];
    self.tabBar.translucent = NO;
}

// 设置不允许屏幕旋转
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (void)setupAllChildViewControllers {
    
    HomeViewController *home = [[HomeViewController alloc] init];
    [self setupChildViewController:home image:[UIImage imageNamed:@"home_normal"] selectImage:[UIImage imageWithOriginalName:@"home_select"] title:@"首页"];
    
    ListViewController *list = [[ListViewController alloc] init];
    [self setupChildViewController:list image:[UIImage imageNamed:@"list_normal"] selectImage:[UIImage imageWithOriginalName:@"list_select"] title:@"列表"];
    
    AlarmViewController *alarm = [[AlarmViewController alloc] init];
    [self setupChildViewController:alarm image:[UIImage imageNamed:@"alarm_normal"] selectImage:[UIImage imageWithOriginalName:@"alarm_select"] title:@"告警"];
    
    MeViewController *me = [[MeViewController alloc] init];
    [self setupChildViewController:me image:[UIImage imageNamed:@"me_normal"] selectImage:[UIImage imageWithOriginalName:@"me_select"] title:@"我的"];
}

/**
 添加子控制器
 
 @param viewController 子控制器
 @param image 图片
 @param selectImage 选中图片
 @param title item的标题
 */
- (void)setupChildViewController:(UIViewController *)viewController image:(UIImage *)image selectImage:(UIImage *)selectImage title:(NSString *)title{
    
    viewController.title = title;
    viewController.tabBarItem.image = image;
    viewController.tabBarItem.selectedImage = selectImage;
    
    NavigationController *nav = [[NavigationController alloc] initWithRootViewController:viewController];
    [self addChildViewController:nav];
}

/**
 *  设置TabbarItem的主题
 */
+ (void)initialize{
    
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    attr[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectedAttr = [NSMutableDictionary dictionary];
    selectedAttr[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    selectedAttr[NSForegroundColorAttributeName] = kBaseColor;
    
    UITabBarItem *items = [UITabBarItem appearance];
        [items setTitlePositionAdjustment:UIOffsetMake(0, -3.)];
    [items setTitleTextAttributes:attr forState:UIControlStateNormal];
    [items setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
